﻿using System;
using Microsoft.WindowsAzure.StorageClient;
using System.ComponentModel.DataAnnotations;

namespace LCA.Community.DAL.Model
{
    /// <summary>
    /// This class contains a comment of a post.
    /// 
    /// RowKey = ID of the comment.
    /// PartitionKey = PostID of the commented post.
    /// </summary>
    public class Comment : BasicDataModel
    {
        #region Fields
        private string authoravatar; 
        #endregion

        /// <summary>
        /// Initializes a new instance of the <see cref="Comment"/> class.
        /// </summary>
        public Comment()
        {

        }

        /// <summary>
        /// Initializes a new instance of the <see cref="Comment"/> class.
        /// </summary>
        /// <param name="post">The post.</param>
        /// <param name="user">The user.</param>
        /// <param name="body">The body.</param>
        public Comment(string post, string user, string body)
        {
            RowKey = Guid.NewGuid().ToString();
            PartitionKey = post;
            Author = user;
            Body = body;
            Date = DateTime.UtcNow;
        }

        /// <summary>
        /// Gets the author avatar.
        /// </summary>
        /// <returns>The author avatar</returns>
        public string GetAuthorAvatar()
        {
            //if (authoravatar == null) authoravatar = LCAComRepositoryFactory.Repository.GetUserAvatar(Author);
            return authoravatar;
        }

        /// <summary>
        /// Gets or sets the post.
        /// </summary>
        /// <value>The post.</value>
        public string Post
        {
            get
            {
                return PartitionKey;
            }
            set
            {
                PartitionKey = value;
            }
        }
        /// <summary>
        /// Gets or sets the author of the comment.
        /// </summary>
        /// <value>The comment's author.</value>
        public string Author { get; set; }
        /// <summary>
        /// Gets or sets the body of the comment.
        /// </summary>
        /// <value>The comment's body.</value>
        [Required(ErrorMessage = "Debe introducir un comentario.")]
        public string Body { get; set; }
        /// <summary>
        /// Gets or sets the date of the comment.
        /// </summary>
        /// <value>The comment's date.</value>
        public DateTime Date { get; set; }

    }
}
